package com.lmonkey.servlet.comment;

import com.lmonkey.servic.COMMENTDao;
import com.lmonkey.shop.COMMENT;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;

@WebServlet("/admin/admin_commentselect")
public class CommentSelect extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置字符集
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=utf-8");
        //制作分页
        int cpage = 1;
        int count = 5;
        //获取用户指定的页面
        String cp = request.getParameter("cp");
        String keyword = request.getParameter("keywords");
        if (cp != null){
            cpage = Integer.parseInt(cp);
        }
        int arr[] = COMMENTDao.tital(count,keyword);
        ArrayList<COMMENT> list = COMMENTDao.selectAll(cpage,count,keyword);

        request.setAttribute("tsum",arr[0]);
        request.setAttribute("tpage",arr[1]);
        request.setAttribute("list",list);
        request.setAttribute("cpage",cpage);

        if (keyword != null){
            request.setAttribute("searchParams","&keywords="+keyword);
        }
        request.getRequestDispatcher("admin_comment.jsp").forward(request,response);
    }
}
